package org.dregs.advice;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestControllerAdvice
public class IndexControllerAdvice {

    @ExceptionHandler(Exception.class)
    public String exceptionHandler(Exception e){
        e.printStackTrace();
        return "{\"code\":-1,\"msg\":\"Server Error\"}";
    }

    //@ExceptionHandler(Exception.class)
    public String exceptionHandler(Exception e, HttpServletResponse response) throws IOException {
        response.setStatus(500);
        e.printStackTrace();
        return "Server Error";
    }

}
